﻿using System.Collections.Generic;
using System.Linq;

namespace Tyshka.Subroutines.Domain.Entities
{
    public partial class Subroutine : IEntity
    {
        public int Votes
        {
            get
            {
                return this.UserVotes == null || this.UserVotes.Count == 0 ? 0 : this.UserVotes.Sum(uv => uv.Amount);
            }
        }

        public List<Subroutine> CompiledAlternatives
        {
            get
            {
                var test =
                    this.Alternatives.Select(a => a.Subroutine1).Union(this.Alternatives1.Select(b => b.Subroutine)).
                        ToList();
                return test;
            }
        }

        public List<Subroutine> CompiledDependencies
        {
            get
            {
                return
                    this.Dependencies.Select(d => d.Subroutine1).Union(this.Dependencies1.Select(e => e.Subroutine)).
                        ToList();
            }
        }
    }
}
